import moment from 'moment'

const dictKey = {
    projectDto: {
        name: '融资需求',
        intellectualList: 'intellectualList', // 专利字段
    },
    financialProductDto: {
        name: '金融产品',
        bankName: '金融机构',
        handleAgency: '办理机构'
    },
    intellAsseDto: {
        name: '知识产权',
        assessmentFile: '评估报告'
    },
    bankLoanDto: {
        name: '银行放款',
        date: '放款时间',
        money: '放款金额',
    },
    payBackPlanDto: {
        name: '企业还款',
        period: '还款期限',
        money: '还款金额'
    }
}


export function filterKey(result) {
    let list = []
    for (let k in result) {
        const item = result[k]
        if (dictKey[k] && item) {
            let common_block = [
                {label: '哈希值', value: item.blockHash.substr(0, 38)},
                {label: '区块链高度', value: item.blockHeight},
                {label: '上链时间', value: moment(Number(item.blockTimestamp)).format('YYYY-MM-DD HH:mm')}
            ]
            switch (k) {
                case 'projectDto':
                    list.push({
                        name: '融资需求',
                        key: 'projectDto',
                        data: [
                            {label: '拟融资金额', value: item.targetAmount},
                            {label: '拟质押知识产权', value: item.intellectualList.map(item => item.name).join('、')},
                        ].concat(common_block)
                    })
                    break
                case 'financialProductDto':
                    list.push({
                        name: '金融产品',
                        key: 'financialProductDto',
                        data: [
                            {label: '产品名称', value: item.productName},
                            {label: '金融机构', value: item.bankName},
                            {label: '办理机构', value: item.handleAgency},
                        ].concat(common_block)
                    })
                    break
                case 'intellAsseDto':
                    list.push({
                        name: '知识产权评估',
                        key: 'intellAsseDto',
                        data: [
                            {label: '评估报告', value: item.assessmentFile},
                        ].concat(common_block)
                    })
                    break
                case 'bankLoanDto':
                    list.push({
                        name: '银行放款',
                        key: 'bankLoanDto',
                        data: [
                            {label: '放款时间', value: moment(new Date(new Date(item.date).getTime()).getTime()).format('YYYY-MM-DD HH:mm') },
                            {label: '放款金额', value: item.money},
                        ].concat(common_block)
                    })
                    break
                case 'payBackPlanDto':
                    list.push({
                        name: '企业还款',
                        key: 'payBackPlanDto',
                        data: [
                            {label: '还款期限', value: item.period},
                            {label: '放款金额', value: item.money},
                        ].concat(common_block)
                    })
                    break
            }
        }
    }
    return list
}
